import java.util.ArrayList;
import java.util.Scanner;
public class test_user {
    public static void main(String[] args) {
        ArrayList<User> user = new ArrayList<>();//建立集合方法
        boolean userbo = false, keybo = false;//判定是用户名还是密码错误，而且优先判断用户名错误
        user.add(new User("jack", "1234"));       //手动输入账号及密码
        for (int i = 0; i < user.size(); i++) {
            System.out.println(user.get(i).username + "-" + user.get(i).keyword);//打印出账号密码，好方便下面的测试
        }
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入用户名：");
        String username = scanner.nextLine();
        System.out.println("请输入密码：");
        String keyword = scanner.nextLine();
        for (int i = 0; i < user.size(); i++) {
            if (username.equals(user.get(i).username) == true) {
                userbo = true;
                if (keyword.equals(user.get(i).keyword) == true) {
                    keybo = true;
                    break;
                }
            }
        }
        System.out.print("登录结果：");
        if (userbo == false)//根据布尔类型的变量来决定输出什么错误提示
            System.out.println("没有该用户");
        else if (keybo == false)
            System.out.println("密码有误");
        else
            System.out.println("登录成功");
    }
}
